package com.gexiaobao.pigeon.ui.adapter

import androidx.appcompat.widget.AppCompatImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.EvaluatedListResponse
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.databinding.ItemEvaluatedListBinding
import com.gexiaobao.pigeon.ui.view.StarRatingBar

/**
 * @Author      : hxw
 * @Date        : 2023/7/8 15:25
 * @Describe    :
 */
class EvaluatedListAdapter(data: ArrayList<EvaluatedListResponse.ListBean>) :
    BaseQuickAdapter<EvaluatedListResponse.ListBean, DataBindBaseViewHolder>(R.layout.item_evaluated_list, data) {

    override fun convert(holder: DataBindBaseViewHolder, item: EvaluatedListResponse.ListBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemEvaluatedListBinding
        binding.data = item
        binding.executePendingBindings()//防止列表抖动

        val ratingStarEvaluatedNum = holder.getView<StarRatingBar>(R.id.ratingStarEvaluatedNum)
        ratingStarEvaluatedNum.setStar(item.goodsRating.toFloat())

        val ivItemEvaluatedGoodImage = holder.getView<AppCompatImageView>(R.id.ivItemEvaluatedGoodImage)
        ImageLoaderManager.loadRoundImageOrEmpty(context, item.goodsImg, ivItemEvaluatedGoodImage, 12, R.drawable.shop_product_def)

        val evaluateContent = item.goodsEvaluate.ifEmpty {
            context.getString(R.string.You_did_not_fill_in_the_evaluation)
        }
        holder.setText(R.id.tvItemEvaluatedContent, evaluateContent)
    }
}